home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 353_02 / enum.cpp < prev    next >
C/C++ Source or Header  |  1992-01-18  |  716b  |  35 lines

  1.                                    // Chapter 2 - Program 1
  2. #include <iostream.h>
  3.  
  4. enum game_result {win, lose, tie, cancel};
  5.  
  6. main()
  7. {
  8. game_result result;
  9. enum game_result omit = cancel;
  10.  
  11.    for (result = win;result <= cancel;result++) {
  12.       if (result == omit) 
  13.          cout << "The game was cancelled\n";
  14.       else {
  15.          cout << "The game was played ";
  16.          if (result == win)
  17.             cout << "and we won!";
  18.          if (result == lose)
  19.             cout << "and we lost.";
  20.          cout << "\n";
  21.       }
  22.    }
  23. }
  24.  
  25.  
  26.  
  27.  
  28. // Result of execution
  29. //
  30. // The game was played and we won!
  31. // The game was played and we lost.
  32. // The game was played
  33. // The game was cancelled
  34.  
  35.